s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
a = [0 for i in range(0, 100000)]
for i in range(0, n):
	a[i] = int(s[i])
# print(a)
ans = 0
r = 0
for i in range(0, n):
	while a[r + 1] - a[i] <= k and r + 1 < n:
		r = r + 1
#		print(i, r)
	ans = ans + (r - i)
print(ans)